<template>
	<view class="content">
		<view class="mineMiddle" v-if="option.s==0">
			<view class="formItem f16" @click="jump(1)">
				<view class="text">发送位置</view>
				<view class="right"> <icon class="iconfont iconarrow-right" type="" /> </view>
			</view>
			<view class="formItem f16" @click="jump(2)">
				<view class="text">已发送</view>
				<view class="right"> <icon class="iconfont iconarrow-right" type="" /> </view>
			</view>
		</view>
		<view class="mineMiddle" v-else>
			<view class="formItem f16" @click="jump_s(1)">
				<view class="text">填写</view>
				<view class="msg" v-show="s_data">{{s_data}}</view>
				<view class="right"> <icon class="iconfont iconarrow-right" type="" /> </view>
			</view>
			<view class="formItem f16" @click="jump_s(2)">
				<view class="text">已填写</view>
				<view class="right"> <icon class="iconfont iconarrow-right" type="" /> </view>
			</view>
		</view>
	</view>
</template>


<script>
	export default {
		
		data() {
			return {
				option:'',
				canSend:false,
				svcRecordId:'',
				errorStatus:false,
				s_data:0
			}
		},
		onLoad(option) {
			console.log('options',option)
			if(option.s==0){
				uni.setNavigationBarTitle({
				　　title:'位置信息'
				})
			}else{
				uni.setNavigationBarTitle({
				　　title:'保修卡'
				})
			}
			this.option=option
		},
		onShow() {
			console.log(this.option)
			this.option.s !=1?this.getPositionStatus():this.getlistCount();
		},
		methods: {
			jump(str){
				this.str = str
				if(this.errorStatus){
					uni.showToast({
						icon:'none',
						title:'服务器错误，稍后重试'
					})
					this.getPositionStatus(str);
					return
				}
				if(!this.canSend && str ==1){
					uni.showModal({
						title: '请查看“已发送”',
						duration: 2000,
						confirmText: '确定',
						showCancel: false,
						confirmColor: '#ff0000',
						success: function(res) {
						}
					});
					return
				}
				if(this.canSend && str ==2){
					uni.showModal({
						title: '请先发送位置信息',
						duration: 2000,
						confirmText: '确定',
						showCancel: false,
						confirmColor: '#ff0000',
						success: function(res) {
						}
					});
					return
				}
				if(this.canSend ==false && str==2){
					uni.navigateTo({
						url:"./sendPlaceDetails?title="+str+"&svcId="+this.option.svcId+'&svcRecordId='+this.svcRecordId
					})
					return
				}
				if(this.canSend ==true && str==1){
					uni.navigateTo({
						url:"./sendPlaceDetails?title="+str+"&svcId="+this.option.svcId
					})
				}
				
			},
			jump_s(str){
				if(str ==1){
					uni.navigateTo({
						url:"../warrantyCard/warrantyPage/warrantyPage_s"
					})
				}else{
					uni.navigateTo({
						url:"../warrantyCard/warrantyPage/warrantyPage_list"
					})
				}
				
			},
			getlistCount(){//锁匠待办
				this.postApi('s_listCount','GET',{loading:true}).then(res=>{
					console.log('res_s',res)
					this.s_data = res.data
				})
			},
			getPositionStatus(str){
				this.postApi('getPositionStatus','GET',{loading:true}).then(res=>{
					console.log('ressss',res)
					if(res.data===null && res.code == 200){
						this.canSend =true
						this.errorStatus=false
						str ? this.jump(str):''
					}else if(res.data.status ==1){
						this.canSend =false
						this.errorStatus=false
						this.svcRecordId = res.data.svcRecordId
						str ? this.jump(str):''
					}else{
						this.errorStatus =true
						uni.showToast({
							icon:'none',
							title:'服务器错误，稍后重试'
						})
					}
					console.log('canSend',this.canSend)
				}).catch(err=>{
					console.log('err ressss',err)
				})
			}
		}
	}
</script>

<style lang="less">
	@import '@/common/common.less';
	.content{
		display: flex;
		flex-direction: column;
		height: 100%;
		.mineMiddle{
			background-color: #FFFFFF;
			.formItem{
				border-bottom: 1rpx solid #e1e1e1;
				display: flex;
				flex-direction: row;
				padding-left: 39rpx;
				height: 101rpx;
				align-items: center;
				position: relative;
				.lefticon{
					margin-right: 28rpx;
					color: @primary-color;
				}
				.text{
					color: #555555;
					margin-right: 21rpx;
				}
				.msg{
					width: 46rpx;
					height: 46rpx;
					border-radius: 50%;
					background-color: #FF0000;
					color: #FFFDEF;
					text-align: center;
					line-height: 46rpx;
				}
				.right{
					position: absolute;
					right: 32rpx;
				}
			}
		}
		.mineBottom{
			margin-top: 18rpx;
			margin-bottom: 23rpx;
		}
	}
	
</style>
